<?php

class Student extends BaseStudent
{
	function __toString()
	{
		return $this->getStdFirstName() . ' ' . $this->getStdLastName();
	}
	
	public function delete(PropelPDO $con = null)
   {
    	parent::delete($con);
		
		if(file_exists(sfConfig::get('sf_upload_dir').'/assets/student/'.utilities::getSpreadPathByDate($this->getCreatedAt()).'/'.$this->getStdAvatarImage())) {
    		unlink(sfConfig::get('sf_upload_dir').'/assets/student/'.utilities::getSpreadPathByDate($this->getCreatedAt()).'/'.$this->getStdAvatarImage());
			unlink(sfConfig::get('sf_upload_dir').'/assets/student/'.utilities::getSpreadPathByDate($this->getCreatedAt()).'/thumb_'.$this->getStdAvatarImage());
			//$datetime = date_create($this->getCreatedAt());
			//$pathDelete = sfConfig::get('sf_upload_dir').'/assets/news/'.date_format($datetime, 'Y/m');
			//utilities::deleteAll($pathDelete, true);
		}
   }
   	// add 20.08.2010  set status  = 0 when it null
	public function save(PropelPDO $con = null) 
	{
		//sfContext::createInstance($this->configuration);
		//$request = sfContext::getInstance()->getRequest();
		$status = $this->getStdStatus();
		if( !isset($status) )
			$this->setStdStatus(0);
		//$response = sfContext::getInstance()->getResponse();  	
		$con->beginTransaction();
		try
		{
			$res = parent::save($con);
			$con->commit();
			return $res;
		} catch (Exception $e) {
			$con->rollBack();
			throw $e;
		}
	}
}
